/**
	ETFRoot project, Anyang Normal University && IMP-CAS
	\class ETFUserVMERawEvent
	\brief class to hold the raw data of a VME event, keeping its original data
	arrangement as in the VME crate
	\author SUN Yazhou, asia.rabbit
	\since 2022-04-27
	\date 2022-04-27 last modified
	\attention
	changelog
	<table>
	<tr>  <th>Date         <th>Author      <th>Description                   </tr>
	<tr>  <td>2022-04-27   <td>Asia Sun    <td>file created                  </tr>
	</table>

	\copyright Copyright (c) 2021 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

#include <iostream>
#include "ETFUserVMERawEvent.h"
#include "ETFMsg.h"

using std::cout;
using std::endl;

ClassImp(ETFUserVMERawEvent);

ETFUserVMERawEvent::ETFUserVMERawEvent() : ETFVMERawEvent(){
	Initialize();
} // end the default constructor

ETFUserVMERawEvent::ETFUserVMERawEvent(const ETFUserVMERawEvent &evt) : ETFVMERawEvent(evt){
	memcpy(fadc, evt.fadc, sizeof(fadc));
	memcpy(fqdc, evt.fqdc, sizeof(fqdc));
} // end the copy constructor

ETFUserVMERawEvent::~ETFUserVMERawEvent(){}

void ETFUserVMERawEvent::Reset(){
	for(int i = 0; i < 32; i++){
		fadc[i] = -9999;
		for(int j = 0; j < 3; j++) fqdc[j][i] = -9999;
	} // end for over i
} // end function initialize

/// reference version ///
int &ETFUserVMERawEvent::adc(int i, int j){
	if(i < 0 || i >= 32) ETFMsg::Warn("ETFUserVMERawEvent", "adc: i(%d) out of bounds ([0-31])", i);
	int &ref = fadc[i];
	return ref;
} // end member function adc
int &ETFUserVMERawEvent::qdc(int i, int j){
	if(i < 0 || i >= 2) ETFMsg::Warn("ETFUserVMERawEvent", "qdc: i(%d) out of bounds ([0-2])", i);
	if(i < 0 || j >= 32) ETFMsg::Warn("ETFUserVMERawEvent", "qdc: j(%d) out of bounds ([0-31])", j);
	int &ref = fqdc[i][j];
	return ref;
} // end member function ETFUserVMERawEvent

void ETFUserVMERawEvent::Print() const{
	for(int i = 0; i < 32; i++) if(fadc[i] != -9999) cout << "adc[" << i << "]" << fadc[i];
	for(int i = 0; i < 32; i++) for(int j = 0; j < 3; j++)
		if(fqdc[j][i] != -9999) cout << "qdc[" << i << "]["<< j << "]: " << fqdc[i][j];
} // end member function Print()
